package level4.tools
{
	public class MathTool
	{
		/**
		 * 归一化处理
		 * */
		public static function normalized(num:Number):void{
			if(num > 1){
				num = 1;
			}else if(num < -1){
				num = -1;
			}
			num = 0;
		}
		
		/**根据概率probability计算是否发生*/
		public static function isHappen(probability:Number):Boolean{
			if(probability <= 0)
				return false;
			if(probability >= 1)
				return true;
			//0< probability < 1
			var bounds:int = Math.round(probability * 100);
			var rands:int = Math.random() * 100;
			if(rands <= bounds)
				return true;
			return false;
		}
		/***参数为 百分比字符*/
		public static  function isHappenPercentString(percentStr:String):Boolean{
			var num:Number = Number(percentStr.substr(0,percentStr.length-1))/100;
			return isHappen(num);
		} 
	}
}